package org.ssp.impl;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.ssp.base.ResultSetHanlder;
import org.ssp.dao.OrderDao;
import org.ssp.pojo.Order;
import org.ssp.util.DBUtil;

public class OrderImpl implements OrderDao {
    //插入订单数据
	@Override
	public void addOrder(Order order) {
		String sql="insert into ordertab values(?,?,?,?,?,?);";
		DBUtil.update(sql, order.getOrderId(),order.getName(),order.getPaytime(),order.getOpenid(),order.getStatus(),order.getTotal_fee());
	}
    //查询orderid订单的状态status
	@Override
	public Order findByOid(String orderid) {
		String sql="select * from ordertab where orderid=?;";
		return (Order)DBUtil.query(sql, new ResultSetHanlder() {
			
			@Override
			public Object doHandler(ResultSet rs) {
				Order order=null;
				try {
					if(rs.next()){
						order =new Order();
						order.setOrderId(rs.getString("orderid"));
						order.setName(rs.getString("name"));
						order.setOpenid(rs.getString("openid"));
						order.setPaytime(rs.getString("paytime"));
						order.setStatus(rs.getInt("status"));
						order.setTotal_fee(rs.getInt("total_fee"));
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return null;
				}
				return order;
			}
		}, orderid);
	}

}
